import piniaPersistConfig from "../../../config/piniaPersist";
import { defineStore } from "pinia";

export const GlobalStore = defineStore({
  id: "GlobalState",
  state: (): STORE.GlobalStore => ({
    // 组件大小
    assemblySize: "middle",
    // language
    language: "ch",
    isCollapse: false,
    currentPageIndex: 0,
    config:{
      layout:'left',
      mode:"light",
      division:true,
      fixedHead:true,
      showTop:true,
      showMenu:true,
      showBread:true,
      themePrimary:'#1890ff', //1890ff
      lock:true,
      fullscreen:true,
      language:true,
      flexd:true,
    }
  }),
  getters: {
    getLanguage(): string {
      return this.language;
    },
  },
  actions: {
    setAssemblySizeSize(assemblySize: 'small' | 'middle' | 'large') {
      this.assemblySize = assemblySize;
    },
    updateLanguage(language: string) {
      this.language = language;
    },
    // 设置导航伸缩
    setCollapse() {
      this.isCollapse = !this.isCollapse;
    },
    // 设置当前激活展示页面
    setCurrentPageIndex(index: number) {
      this.currentPageIndex = index
    },
    setConfig(config:STORE.GlobalStore['config']){
      this.config = config
    },
    setMode(mode:STORE.GlobalStore['config']['mode']){
      this.config.mode = mode
    }
  },
  persist: piniaPersistConfig("GlobalState")
});
